package cn.ieayinfo.train.mybooks.Service;

import cn.ieayinfo.train.mybooks.Entity.Book;
import cn.ieayinfo.train.mybooks.Repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    private BookRepository bookRepository;

    public Book findBookById(Long id) {
        return bookRepository.findBookById(id);
    }
    public List<Book> getBookListByUid(Long uid) {
        return bookRepository.findByCreatoruid(uid);
    }

    public Book save(Book book) {
        return bookRepository.save(book);
    }
    public Boolean deleteById(Long id) {
        try {
            bookRepository.deleteById(id);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public List<Book> getShareBookList() {
        return bookRepository.findByIsShare(true);
    }
}
